package site.koudai.cloud.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.koudai.cloud.annotation.DataResource;
import site.koudai.cloud.common.Result;
import site.koudai.cloud.entity.Order;
import site.koudai.cloud.service.OrderService;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @GetMapping
    @DataResource(value = "order:list", type = Order.class)
    public Result<List<Order>> findAll() {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        return Result.success(orderService.list(queryWrapper));
    }

    @GetMapping("/custom")
    @DataResource(value = "order:custom", type = Order.class)
    public Result<List<Order>> customList() {
        return Result.success(orderService.customList());
    }

    @GetMapping("/{id}")
    @DataResource(value = "order:detail", type = Order.class)
    public Result<Order> getById(@PathVariable Integer id) {
        return Result.success(orderService.getById(id));
    }

    @GetMapping("/page")
    @DataResource(value = "order:page", type = Order.class)
    public Result<IPage<Order>> findByPage() {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        return Result.success(orderService.page(new Page<>(1, 10), queryWrapper));
    }

}
